package com.chris.module.webclient.core;

import com.chris.module.webclient.dto.ConfigDTO;

import java.util.HashMap;
import java.util.Map;

public class WebClientDataSouce {
    Map<String, WebClientUnit> data = new HashMap<>();

    /**
     * 加入WebClientUnit实例
     * @param config
     */
    public void addDataSource(ConfigDTO config)
    {
        WebClientUnit webClientUnit = new WebClientUnit(config);
        data.put(config.getName(),webClientUnit);
    }

    /**
     * 移除WebClientUnit
     * @param name
     */
    public void rmoveDataSource(String name)
    {
        if (data.containsKey(name))
            data.remove(name);
    }

    /**
     * 获取指定名字WebClientUnit
     * @param name
     * @return
     */
    public WebClientUnit getWebClientUnit(String name)
    {
        return  data.get(name);
    }

    /**
     * 默认获取第一个
     * @return
     */
    public WebClientUnit get() {
        if (data.size() > 0)
            return data.get(0);
        else
            return null;
    }

}
